public class test5 {
    public static void main(String[] args) {
        int count = 0;
        int tmp = 1;
        while(count < 23) {
            String arr1 = Integer.toBinaryString(tmp);
            String arr2 = Integer.toOctalString(tmp);
            int a1 = 0;
            int a2 = 0;
            for(int i = 0; i < arr1.length();i++) {
                a1 += arr1.charAt(i) - '0';
            }
            for(int i = 0; i < arr2.length();i++) {
                a2 += arr2.charAt(i) - '0';
            }
            if(a1 == a2) {
                count++;
            }
            tmp++;
        }
        System.out.println(tmp - 1);
    }
}
